#!/bin/bash

source /home/shell/util.sh

# 安装软件
apt update
apt install -y git network-manager lrzsz firewalld apt-file ethstatus iftop libwww-perl make build-essential pkg-config sysfsutils lsb-core sshpass expect unzip sysstat db-util libpam0g-dev lvm2 tree
apt -y upgrade
apt -y autoremove
apt-get autoclean

# 配置软件
## apt-file
apt-file update

## git配置
git config --system --unset credential.helper
git config --global credential.helper store
git config --global user.name "江路"
git config --global user.email jlcon@qq.com
git config --global core.longpaths true
git config --global http.sslVerify false
git config --global pull.rebase false
git --version

## file open配置
echo "root soft nofile 204800">>/etc/security/limits.conf
echo "root hard nofile 204800">>/etc/security/limits.conf
echo "root soft nproc 204800">>/etc/security/limits.conf
echo "root hard nproc 204800">>/etc/security/limits.conf

sed -i "s/#DefaultLimitNOFILE=/DefaultLimitNOFILE=204800/g" /etc/systemd/user.conf
sed -i "s/#DefaultLimitNOFILE=1024:524288/DefaultLimitNOFILE=204800/g" /etc/systemd/system.conf
# sed -i "s/#DefaultTimeoutStartSec=90s/DefaultTimeoutStartSec=3s/" /etc/systemd/system.conf
# sed -i "s/#DefaultTimeoutStopSec=90s/DefaultTimeoutStopSec=3s/" /etc/systemd/system.conf
systemctl daemon-reload

## 设置时区
# cp /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
timedatectl set-timezone Asia/Shanghai
# 自动同步时间
timedatectl set-ntp true
# 系统时间同步到硬件时间
hwclock -w

## network-manager配置
sed -ri "s/managed=false/managed=true/" /etc/NetworkManager/NetworkManager.conf
systemctl restart NetworkManager
sed -i "/network:/a\  renderer: NetworkManager" /etc/netplan/*.yaml
netplan apply
nmcli connection show

printInfo "===================初始化结果==================="
printInfo "硬件时间：`hwclock`"
printInfo "===================初始化结果==================="